import java.util.Arrays;
import java.util.Scanner;
class PersonSortable implements Comparable<PersonSortable>{
	public int compareTo(PersonSortable o){
		 if(name.compareTo(o.name)==0){
			 if(age>o.age)
			 return age-o.age;	 
			 if(age==o.age)
				 return 0;
			 else
				 return -1;
		 }
		 else return name.compareTo(o.name);
	}
	private String name;
	private int age;
	@Override
	public String toString() {
		return name+"-"+age;
	}
	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	
}
public class Main {
    
	public static void main(String[] args) {
		// TODO Auto-generated method stub
   Scanner in=new Scanner(System.in);
   int t=in.nextInt();
   PersonSortable[] a=new PersonSortable[t];
   for(int i=0;i<t;i++)
 { PersonSortable perpll=new PersonSortable(in.next(),in.nextInt());
   a[i]=perpll;
 }
   Arrays.sort(a);
   for(int i=0;i<t;i++)
   System.out.println(a[i]);
   System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}